package cn.com.bluemoon.daps.common.enums;

import cn.com.bluemoon.daps.common.mp.BaseBmEnum;
import cn.hutool.core.util.EnumUtil;

/**
 * 同步环境
 */
public enum SyncToEnv implements BaseBmEnum<Integer> {
    /**
     * 同步到模型、开发、测试、预发布、生产
     * 数据源环境，1-4表示开发、测试、预生产、生产
     * 其中模型为0（其中对应的数据源是开发库环境）
     * bizDesc：业务定义
     */
    MODEL(0, "模型", false, "开发同步"),
    DEV(1, "开发", true, "开发同步"),
    TEST(2, "测试", true, "开发同步"),
//    SANDBOX(-1, "沙箱", false, "发布同步"),
    PRE_PROD(3, "预发布", false, "发布同步"),
    PROD(4, "生产", false, "发布同步"),
//    MODEL_VERSION_NEWEST(5, "模型版本最新", false, "同步管理"),
    /**
     * 增加申请发布中的同步环境，为None，不依赖环境连接
     */
    NONE(-1, "无", false, "申请发布");
    private final Integer code;
    private final String desc, bizDesc;
    private final boolean syncPreCompareResult2DB;

    SyncToEnv(Integer code, String desc, boolean syncPreCompareResult2DB, String bizDesc) {
        this.code = code;
        this.desc = desc;
        this.syncPreCompareResult2DB = syncPreCompareResult2DB;
        this.bizDesc = bizDesc;
    }

    public String getBizDesc() {
        return bizDesc;
    }

    public boolean isSyncPreCompareResult2DB() {
        return syncPreCompareResult2DB;
    }

    public Integer getCode() {
        return code;
    }

    public String getDesc() {
        return desc;
    }

    public String getDescEnv(){
        return this.desc +"环境";
    }

    public String getDescEnv(boolean isProdEnv){
        return this.desc +"环境" + (isProdEnv ? "（生产）" : "（测试）");
    }

    public static SyncToEnv valOf(Integer code) {
        SyncToEnv syncToEnv = EnumUtil.likeValueOf(SyncToEnv.class, code);
        return syncToEnv;
    }

    public boolean isPublishSync(){
        return this.code == 3 || this.code == 4;
    }

    public boolean isDevSync(){
        return this.code == 1 || this.code == 2;
    }

    public static void main(String[] args) {
        System.out.println(SyncToEnv.valOf(1).equals(SyncToEnv.DEV));
    }

    /**
     * 枚举数据库存储值
     */
    @Override
    public Integer getValue() {
        return this.code;
    }
}
